let index = 0
export function request(params){
    let header = {}
    // 判断是否需要token
    if(params.url.includes("/my/")){
        header ={
            Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
        }
    }
    wx.showLoading({
        title:"数据加载中"
    })
    index++
    const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
    return new Promise((resolve,reject)=>{
        wx.request({
            ...params,
            header:header,
            url:baseUrl+params.url,
            success:(res)=>{
                resolve(res)
            },
            fail:(err)=>{
                reject(err)
            },
            complete:()=>{
                index--;
                if(index!=0) return
                wx.hideLoading()
            }
        })
    })
}

